/*
 * Teknei 2014 - All rights reserved
 */
package com.teknei.acabus.example.services.impl;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import com.teknei.acabus.PersistenceException;
import com.teknei.acabus.ServiceException;
import com.teknei.acabus.core.entities.TableB;
import com.teknei.acabus.core.persistence.dao.TableBDAO;
import com.teknei.acabus.example.services.TableBService;

/**
 * Session Bean implementation class TableBServiceBean
 * @author Jorge Amaro
 * @version 1.0
 * @since 1.0
 */
@Stateless
public class TableBServiceBean implements TableBService {

	@EJB
	private TableBDAO daoTableB;
	
	/* (non-Javadoc)
	 * @see com.teknei.acabus.example.services.TableBService#findAll()
	 */
	@Override
	public List<TableB> findAll() throws ServiceException{
		try{
			List<TableB> list = daoTableB.findAll();
			return list;
		}catch(PersistenceException e){
			throw new ServiceException("Error in findAll:"+e.getMessage(), e);
		}
	}
	
	/* (non-Javadoc)
	 * @see com.teknei.acabus.example.services.TableBService#update(com.teknei.acabus.core.entities.TableB)
	 */
	@Override
	public void update(TableB entity) throws ServiceException{
		try{
			daoTableB.update(entity);
		}catch(PersistenceException e){
			throw new ServiceException("Error in update:"+e.getMessage(), e);
		}
	}
	
	/* (non-Javadoc)
	 * @see com.teknei.acabus.example.services.TableBService#save(com.teknei.acabus.core.entities.TableB)
	 */
	@Override
	public int save(TableB entity) throws ServiceException{
		try{
			TableB savedInstance = daoTableB.create(entity);
			return savedInstance.getIdField();
		}catch(PersistenceException e){
			throw new ServiceException("Error in save:"+e.getMessage(), e);
		}
	}
	
	/* (non-Javadoc)
	 * @see com.teknei.acabus.example.services.TableBService#delete(com.teknei.acabus.core.entities.TableB)
	 */
	@Override
	public void delete(TableB entity) throws ServiceException{
		try{
			daoTableB.delete(entity);
		}catch(PersistenceException e){
			throw new ServiceException("Error in delete:"+e.getMessage(), e);
		}
	}
	

	/**
	 * @return the daoTableA
	 */
	public TableBDAO getDaoTableB() {
		return daoTableB;
	}

	/**
	 * @param daoTableA the daoTableA to set
	 */
	public void setDaoTableB(TableBDAO daoTableB) {
		this.daoTableB = daoTableB;
	}

}
